﻿// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.

namespace Microsoft.Samples.Commerce.Order
{
    using System;
    using Microsoft.Commerce.Common;
    using Microsoft.Commerce.Common.MessageBuilders;
    using Microsoft.Commerce.Contracts.Messages;

    /// <summary>
    /// This is a helper class that facilitates calls to the Commerce Foundation service.
    /// The code in this class is not production ready and is intended to supplement the 
    /// Commerce Foundation Order APIs sample.
    /// </summary>
    public static class CommerceFoundationServiceAgent
    {
        /// <summary>
        /// Sample user Id.
        /// </summary>
        public const string UserId = "7139F631-D037-493f-A658-0CC75377FB08";

        /// <summary>
        /// Sample channel name.
        /// </summary>
        public const string Channel = "SampleChannel";

        /// <summary>
        /// Service agent instance.
        /// </summary>
        private static OperationServiceAgent operationServiveAgent = new OperationServiceAgent();

        /// <summary>
        /// Executes the specified operation.
        /// </summary>
        /// <param name="operation">The operation.</param>
        /// <returns>The response instance.</returns>
        public static CommerceResponse Execute(CommerceBaseBuilder operation)
        {
            ParameterChecker.CheckForNull(operation, "operation");

            return CommerceFoundationServiceAgent.operationServiveAgent.ProcessRequest(
                GetCurrentRequestContext(), operation.ToRequest());
        }

        /// <summary>
        /// Gets the current request context.
        /// </summary>
        /// <returns>A request context instance.</returns>
        private static CommerceRequestContext GetCurrentRequestContext()
        {
            CommerceRequestContext requestContext = new CommerceRequestContext()
            {
                Channel = Channel,
                UserId = UserId,
                UserLocale = "en-US",
                UserUILocale = "en-US",
                RequestId = Guid.NewGuid().ToString()
            };

            return requestContext;
        }
    }
}
